package com.ruoyi.settled.controller;

import com.ruoyi.settled.domain.GroupLeaderOrders;
import com.ruoyi.settled.service.IGroupLeaderOrdersService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 团长订单Controller
 * 
 * @author ruoyi
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/GroupLeaderOrders/GroupLeaderOrders")
public class GroupLeaderOrdersController extends BaseController
{
    @Autowired
    private IGroupLeaderOrdersService groupLeaderOrdersService;

    /**
     * 查询团长订单列表
     */
    @PreAuthorize("@ss.hasPermi('GroupLeaderOrders:GroupLeaderOrders:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupLeaderOrders groupLeaderOrders)
    {
        startPage();
        List<GroupLeaderOrders> list = groupLeaderOrdersService.selectGroupLeaderOrdersList(groupLeaderOrders);
        return getDataTable(list);
    }

    /**
     * 导出团长订单列表
     */
    @PreAuthorize("@ss.hasPermi('GroupLeaderOrders:GroupLeaderOrders:export')")
    @Log(title = "团长订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupLeaderOrders groupLeaderOrders)
    {
        List<GroupLeaderOrders> list = groupLeaderOrdersService.selectGroupLeaderOrdersList(groupLeaderOrders);
        ExcelUtil<GroupLeaderOrders> util = new ExcelUtil<GroupLeaderOrders>(GroupLeaderOrders.class);
        util.exportExcel(response, list, "团长订单数据");
    }

    /**
     * 获取团长订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('GroupLeaderOrders:GroupLeaderOrders:query')")
    @GetMapping(value = "/{orderCode}")
    public AjaxResult getInfo(@PathVariable("orderCode") String orderCode)
    {
        return success(groupLeaderOrdersService.selectGroupLeaderOrdersByOrderCode(orderCode));
    }

    /**
     * 新增团长订单
     */
    @PreAuthorize("@ss.hasPermi('GroupLeaderOrders:GroupLeaderOrders:add')")
    @Log(title = "团长订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupLeaderOrders groupLeaderOrders)
    {
        return toAjax(groupLeaderOrdersService.insertGroupLeaderOrders(groupLeaderOrders));
    }

    /**
     * 修改团长订单
     */
    @PreAuthorize("@ss.hasPermi('GroupLeaderOrders:GroupLeaderOrders:edit')")
    @Log(title = "团长订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupLeaderOrders groupLeaderOrders)
    {
        return toAjax(groupLeaderOrdersService.updateGroupLeaderOrders(groupLeaderOrders));
    }

    /**
     * 删除团长订单
     */
    @PreAuthorize("@ss.hasPermi('GroupLeaderOrders:GroupLeaderOrders:remove')")
    @Log(title = "团长订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderCodes}")
    public AjaxResult remove(@PathVariable String[] orderCodes)
    {
        return toAjax(groupLeaderOrdersService.deleteGroupLeaderOrdersByOrderCodes(orderCodes));
    }
}
